package simple3D.core 
{
	import flash.display.Shape;
	import flash.display.TriangleCulling;
	import flash.geom.Point;
	import flash.geom.Vector3D;
	/**
	 * ...
	 * @author Dmitriy Gaiduk
	 */
	public class ShapeTest extends Shape
	{
		private var points:Vector.<Vector3D>;
		private var indices:Vector.<int>;
		private var uvt:Vector.<Number>;
		
		public function ShapeTest(points:Vector.<Vector3D>, indices:Vector.<int>, uvt:Vector.<Number>) 
		{
			super();
			this.points = points;
			this.indices = indices;
			this.uvt = uvt;
		}
		
		public function update():void
		{
			for each (var v:Vector3D in points)
			{
				graphics.beginFill(0xCCCCCC, 1);
				graphics.drawCircle(v.x, v.y, 5);
				graphics.endFill();
			}
			
			var index:int = 0;
			var len:int = indices.length;
			
			while (index < len)
			{
				graphics.beginFill(getColor((index+3)*5, (index+3)*5, (index+3)*5));
				graphics.lineStyle(1, 0x00FF00);
				graphics.moveTo(points[indices[index]].x, points[indices[index]].y);
				graphics.lineTo(points[indices[index+1]].x, points[indices[index+1]].y);
				graphics.lineTo(points[indices[index+2]].x, points[indices[index+2]].y);
				graphics.moveTo(points[indices[index]].x, points[indices[index]].y);
				graphics.endFill();
				
				index += 3;
			}
			
			//shape line
			graphics.lineStyle(4, 0xFF0000);
			len = points.length;
			graphics.moveTo(points[0].x, points[0].z);
			for (var i:int = 1; i < len-1; i++)
			{
				graphics.lineTo(points[i].x, points[i].z);
			}
			
		}
		
		private function getColor(red:uint, green:uint, blue:uint):uint
		{
			return red << 16 | green << 8 | blue;
		}
		
	}

}